package com.eningqu.aipen.ui.medical;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.eningqu.aipen.demo.R;
import com.eningqu.aipen.demo.databinding.ActivityMedicalDetailsBinding;
import com.eningqu.aipen.logic.model.medical.MedicalBookBean;
import com.eningqu.aipen.logic.model.medical.MedicalNodeWithXyModelBean;
import com.eningqu.aipen.ui.adapter.GridNineAdapter;
import com.eningqu.aipen.ui.base.BaseActivity;
import com.kongzue.dialogx.dialogs.FullScreenDialog;
import com.kongzue.dialogx.dialogs.PopMenu;
import com.kongzue.dialogx.interfaces.OnBindView;

import java.util.ArrayList;
import java.util.Arrays;

/**
 * Package:com.eningqu.aipen.ui.medical
 * Author:starr
 * Time:2023/11/20 19:53
 * Description: 病历详情信息
 */
public class MedicalDetailActivity extends BaseActivity<ActivityMedicalDetailsBinding> {

    private static MedicalNodeWithXyModelBean.JdListDTO.ModelEntityDTO nodeBean;
    private static MedicalBookBean.PageDTO patient;


    private RecyclerView rvNine;

    public static void startAction(Context context, Bundle bundle) {
        Intent intent = new Intent(context, MedicalDetailActivity.class);
        nodeBean = (MedicalNodeWithXyModelBean.JdListDTO.ModelEntityDTO) bundle.getSerializable("nodeBean");
        patient = (MedicalBookBean.PageDTO) bundle.getSerializable("patient");
        context.startActivity(intent);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_medical_details;
    }

    @Override
    protected void initView() {

        mBinding.titleTopBar.baseTvTitle.setText("西医病历");
        mBinding.titleTopBar.baseIvBack.setOnClickListener(v -> finish());
        mBinding.titleTopBar.baseIvBack.setVisibility(View.VISIBLE);

        mBinding.tvName.setText(patient.hzInfoEntity.emrHzName);
        mBinding.tvAge.setText(patient.hzInfoEntity.emrHzAge.toString());
        mBinding.tvSex.setText(patient.hzInfoEntity.emrHzSex);
        mBinding.tvKs.setText(nodeBean.emrXyKs);

        mBinding.etAction.setText(nodeBean.emrXyMain);
        mBinding.etAdvice.setText(nodeBean.emrXyDeal);//处方
        mBinding.etData.setText(nodeBean.emrXyCheck);//检查资料
        mBinding.etHistory.setText(nodeBean.emrXyBefore);
        mBinding.etNow.setText(nodeBean.emrXyNow);
        mBinding.etDiagnosis.setText(nodeBean.emrXyGm);//过敏

        mBinding.setClick(new DetailClick());
        rvNine = mBinding.rvNine;
        rvNine.setLayoutManager(new GridLayoutManager(getContext(),3));
    }

    @Override
    protected void initData() {

        ArrayList<String> list=new ArrayList<>();
        if(nodeBean.emrXyImgs!=null){
            mBinding.tvPic.setVisibility(View.VISIBLE);
            String[] strs=nodeBean.emrXyImgs.split(";");
            list.addAll(Arrays.asList(strs));
        }
        GridNineAdapter adapter=new GridNineAdapter(list);
        rvNine.setAdapter(adapter);


    }

    @Override
    protected void async() {

    }


    @SuppressWarnings("unused")
    public class DetailClick {

        public void chooseKs(View view) {
            mBinding.tvKs.setOnClickListener(v -> PopMenu.show(v, new String[]{"外科", "内科", "呼吸科", "其他"})
                    .setOnMenuItemClickListener((popMenu, text, i) -> {
                        mBinding.tvKs.setText(text);
                        return false;
                    }));
        }

        public void back(View view) {
            finish();
        }

        public void change(View view) {
            loadDialog();
        }

    }

    public void loadDialog() {
        FullScreenDialog.show(new OnBindView<FullScreenDialog>(R.layout.dialog_change) {
            @Override
            public void onBind(FullScreenDialog customDialog, View view) {
                ImageView ivPic;
                ivPic = view.findViewById(R.id.iv_pic);
                Glide.with(view).load(nodeBean.emrXyImg).into(ivPic);
            }
        });
    }

}
